package demo2;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-06-21
 * Time: 9:45
 */
class Solution1 {
    public boolean backspaceCompare(String s, String t) {
        int skipS = 0;
        int skipT = 0;
        int i = s.length()-1;
        int j = s.length()-1;
        while(i>=0||j>=0){
            while(i>=0){
                if(s.charAt(i)=='#'){
                    skipS++;
                    i--;
                }else if(skipS>0){
                    skipS--;
                    i--;
                }else {
                    break;
                }
            }
            while(j>=0){
                if(t.charAt(j)=='#'){
                    skipT++;
                    j--;
                }else if(skipT>0){
                    skipT--;
                    j--;
                }else {
                    break;
                }
            }
            //接下来开始进行比较
            if(i>=0&&j>=0){
                if(s.charAt(i)!=t.charAt(j)){
                    return false;
                }
            }else {
                if((i>=0&&j<0)||(i<0&&j>=0)){
                    return false;
                }
            }
            i--;
            j--;
        }
        return true;
    }
}

class Solution5 {
    public boolean validMountainArray(int[] arr) {
        int left =0;
        int right = arr.length-1;
        while(left<right){
            if(left<right&&arr[left]>=arr[left+1]){
                return false;
            }else {
                left++;
            }
            if(left<right&&arr[right]>=arr[right-1]){
                return false;
            }else {
                right--;
            }
        }
        return true;
    }
}

class Solution {
    public int[] intersection(int[] nums1, int[] nums2) {
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        int index1 =0;
        int index2 =0;
        int length1 = nums1.length-1;
        int length2 = nums2.length-1;
        int[] res = new int[nums1.length>nums2.length?nums2.length:nums1.length];
        int i = 0;
        while(index1<=length1&&index2<=length2){
            if(nums1[index1]==nums2[index2]){
                if(i==0){
                    res[i] = nums1[index1];
                    i++;
                }
                if(i>0&&res[i-1]!=nums1[index1]){
                    res[i] = nums1[index1];
                    i++;
                }
                index1++;
                index2++;
            }else if(nums1[index1]>nums2[index2]){
                index2++;
            }else {
                index1++;
            }
        }
        return Arrays.copyOfRange(res, 0, i);
    }
}
public class TestDemo {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums1 ={1};
        int[] nums2 ={1};
        solution.intersection(nums1,nums2);
        Arrays.copyOfRange
    }

}
